package com.cw.jeeyt.service.converter.api;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.service.bo.api.ApiDatabaseDocConfigBo;
import com.cw.jeeyt.dao.model.api.ApiDatabaseDocConfigDo;
import com.cw.lang.common.utils.CollectionUtil;

/**
 * 数据库文档生成配置转换类
 *
 * @author chenw
 * @date 2019-03-10 13:05:36
 */
public class ApiDatabaseDocConfigConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static ApiDatabaseDocConfigBo do2Bo(ApiDatabaseDocConfigDo model) {
        if (model == null) {
            return null;
        }
        ApiDatabaseDocConfigBo bo = new ApiDatabaseDocConfigBo();
        bo.setId(model.getId());
        bo.setDatabaseId(model.getDatabaseId());
        bo.setDatabaseCode(model.getDatabaseCode());
        bo.setGenerateTablePrefix(model.getGenerateTablePrefix());
        bo.setGenerateDocType(model.getGenerateDocType());
        bo.setGenerateDocColorStyle(model.getGenerateDocColorStyle());
        bo.setPublishAuthor(model.getPublishAuthor());
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static ApiDatabaseDocConfigDo bo2Do(ApiDatabaseDocConfigBo bo) {
        if (bo == null) {
            return null;
        }
        ApiDatabaseDocConfigDo model = new ApiDatabaseDocConfigDo();
        model.setId(bo.getId());
        model.setDatabaseId(bo.getDatabaseId());
        model.setDatabaseCode(bo.getDatabaseCode());
        model.setGenerateTablePrefix(bo.getGenerateTablePrefix());
        model.setGenerateDocType(bo.getGenerateDocType());
        model.setGenerateDocColorStyle(bo.getGenerateDocColorStyle());
        model.setPublishAuthor(bo.getPublishAuthor());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<ApiDatabaseDocConfigBo> doList2BoList(List<ApiDatabaseDocConfigDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), ApiDatabaseDocConfigConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<ApiDatabaseDocConfigDo> boList2DoList(List<ApiDatabaseDocConfigBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), ApiDatabaseDocConfigConverter::bo2Do));
    }
}